local extension = Package("rfenghou_han")
extension.extensionName = "aaa_fenghou"

local U = require "packages/utility/utility"
local DIY = require "packages/diy_utility/diy_utility"


Fk:loadTranslationTable{
  ["rfenghou_han"] = "衰汉",
  ["han"] = "汉",
}
Fk:appendKingdomMap("god", {"han"})

local function AddWinAudio(general)
  local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
  Win.package = extension
  Fk:addSkill(Win)
end

--FY004 冯习张南 by朱苦力
local fengxizhangnan = General:new(extension, "rfenghou__fengxizhangnan", "han", 4)
local zhangnan = fk.CreateTriggerSkill{
  name = "rfenghou__zhangnan",
  anim_type = "defensive",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and player:hasSkill(self) and player:getMark("@@rfenghou_readying:::"..self.name) == 0 and
      not target.dead and (target.seat < player.seat or target:getAttackRange() < player:getAttackRange())
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__zhangnan-invoke:"..target.id..":"..data.to.id) then
      self.cost_data = {tos = {data.to.id}}
      return true
    end
  end,
  on_use = Util.TrueFunc,

  refresh_events = {"fk.RfenghouSkillNulli", "fk.RfenghouSkillReady", fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    if target == player and data == self then
      if event == "fk.RfenghouSkillNulli" then
        return true
      else
        return player:hasSkill("rfenghou__fengxi", true)
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == "fk.RfenghouSkillNulli" then
      room:handleAddLoseSkills(player, "rfenghou__fengxi", nil, true, false)
    else
      room:handleAddLoseSkills(player, "-rfenghou__fengxi", nil, true, false)
    end
  end,
}
zhangnan.RfenghouReadySkill = true
local fengxi = fk.CreateActiveSkill{
  name = "rfenghou__fengxi",
  anim_type = "offensive",
  card_num = 0,
  min_target_num = 1,
  max_target_num = 2,
  prompt = "#rfenghou__fengxi",
  can_use = function(self, player)
    return player:getMark("@@rfenghou_readying:::"..self.name) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected < 2 and (Fk:currentRoom():getPlayerById(to_select).seat > Self.seat or
      Fk:currentRoom():getPlayerById(to_select).hp > Self.hp)
  end,
  feasible = function (self, selected, selected_cards)
    if #selected == 1 then
      return true
    elseif #selected == 2 then
      if Fk:currentRoom():getPlayerById(selected[1]).seat > Self.seat and
        Fk:currentRoom():getPlayerById(selected[1]).hp > Self.hp then
        return true
      else
        if Fk:currentRoom():getPlayerById(selected[1]).seat > Self.seat then
          return Fk:currentRoom():getPlayerById(selected[2]).hp > Self.hp
        else
          return Fk:currentRoom():getPlayerById(selected[2]).seat > Self.seat
        end
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:sortPlayersByAction(effect.tos)
    for _, id in ipairs(effect.tos) do
      local p = room:getPlayerById(id)
      if not p.dead then
        room:damage{
          from = player,
          to = p,
          damage = 1,
          skillName = self.name,
        }
      end
    end
  end,
}
fengxi.RfenghouReadySkill = true
local fengxi_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__fengxi_trigger",
  mute = true,
  events = {"fk.RfenghouSkillReady"},
  can_trigger = function (self, event, target, player, data)
    return target == player and data == fengxi
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:drawCards(3, "rfenghou__fengxi")
  end,
}
fengxi:addRelatedSkill(fengxi_trigger)
fengxizhangnan:addSkill(zhangnan)
fengxizhangnan:addRelatedSkill(fengxi)
Fk:loadTranslationTable{
  ["rfenghou__fengxizhangnan"] = "冯习张南",
  ["#rfenghou__fengxizhangnan"] = "火中躯砺",
  ["illustrator:rfenghou__fengxizhangnan"] = "食茸",
  ["designer:rfenghou__fengxizhangnan"] = "zzcclll朱苦力",

  ["rfenghou__zhangnan"] = "障南",
  [":rfenghou__zhangnan"] = "<a href='rfenghou_ready_skill'>蓄势技</a>，座次或攻击范围小于你的角色造成伤害时，你可以防止之。此技能行置期间，"..
  "你视为拥有技能〖锋西〗。",
  ["rfenghou__fengxi"] = "锋西",
  [":rfenghou__fengxi"] = "<a href='rfenghou_ready_skill'>蓄势技</a>，出牌阶段，你可以对一名座次大于你和一名体力值大于你的角色各造成1点伤害。"..
  "此技能重置时，你摸三张牌。",
  ["#rfenghou__zhangnan-invoke"] = "障南：是否防止 %src 对 %dest 造成的伤害？",
  ["#rfenghou__fengxi"] = "锋西：对一名座次大于你和一名体力值大于你的角色各造成1点伤害",
  ["@@rfenghou_readying:::rfenghou__zhangnan"] = "障南失效",
  ["@@rfenghou_readying:::rfenghou__fengxi"] = "锋西失效",

  ["$rfenghou__zhangnan1"] = "柱石七尺，鼠辈岂可逾越？",
  ["$rfenghou__zhangnan2"] = "摧城破敌，吴贼不足挂齿。",
  ["$rfenghou__fengxi1"] = "男儿当封侯，焉能守旧丘。",
  ["$rfenghou__fengxi2"] = "落日照大旗，出师亘长云！",
  ["~rfenghou__fengxizhangnan"] = "殁于王事，我等无憾。",
}

--FY005 刘岱 by白驹
local liudai = General:new(extension, "rfenghou__liudai", "han", 4)
local shuzhou = fk.CreateTriggerSkill{
  name = "rfenghou__shuzhou",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and #player.room.alive_players > 1
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__shuzhou-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room:getOtherPlayers(player), Util.IdMapper))
    room.tag[self.name] = room.tag[self.name] or {}
    if room.tag[self.name][string.format("%.0f", player.id)] then
      local record = room.tag[self.name][string.format("%.0f", player.id)]
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if table.contains(record[1], p.id) then
          room:removePlayerMark(p, "@rfenghou__shuzhou_give", 1)
        elseif table.contains(record[2], p.id) then
          room:removePlayerMark(p, "@rfenghou__shuzhou_nogive", 1)
        end
      end
    end
    local record = {{}, {}}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if player.dead then break end
      if not p.dead then
        if p:isNude() then
          room:addPlayerMark(p, "@rfenghou__shuzhou_nogive", 1)
          table.insert(record[2], p.id)
        else
          local card = room:askForCard(p, 1, 1, true, self.name, true, nil, "#rfenghou__shuzhou-give:"..player.id)
          if #card > 0 then
            room:addPlayerMark(p, "@rfenghou__shuzhou_give", 1)
            table.insert(record[1], p.id)
            room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false, p.id)
          else
            room:addPlayerMark(p, "@rfenghou__shuzhou_nogive", 1)
            table.insert(record[2], p.id)
          end
        end
      end
    end
    room.tag[self.name][string.format("%.0f", player.id)] = record
  end,

  refresh_events = {fk.DamageCaused},
  can_refresh = function (self, event, target, player, data)
    return target and target == player and player.room.tag[self.name]
  end,
  on_refresh = function (self, event, target, player, data)
    local n = 0
    for _, record in pairs(player.room.tag[self.name]) do
      if table.contains(record[1], player.id) and table.contains(record[2], data.to.id) then
        n = n + 1
      end
      if table.contains(record[2], player.id) and table.contains(record[1], data.to.id) then
        n = n + 1
      end
    end
    data.damage = data.damage + n
  end,
}
--[[local liye = fk.CreateViewAsSkill{
  name = "rfenghou__liye",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#rfenghou__liye",
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      return true
    elseif #selected == 1 then
      return Fk:getCardById(to_select).suit == Fk:getCardById(selected[1]).suit
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then return end
    local card = Fk:cloneCard("slash")
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local all_targets = table.simpleClone(TargetGroup:getRealTargets(use.tos))
    local tos = table.simpleClone(all_targets)
    room:broadcastPlaySound("./packages/standard_cards/audio/card/"..(player.gender == General.Male and "male" or "female").."/slash")
    room:doIndicate(player.id, tos)
    for _, id in ipairs(TargetGroup:getRealTargets(use.tos)) do
      local to = room:getPlayerById(id)
      while to ~= player do
        local targets = table.filter(room:getOtherPlayers(player), function (p)
          return not table.contains(all_targets, p.id) and not player:isProhibited(p, use.card)
        end)
        if #targets > 0 then
          local t = room:askForChoosePlayers(to, table.map(targets, Util.IdMapper), 1, 1,
            "#rfenghou__liye-choose:"..player.id, self.name, true)
          if #t > 0 then
            table.insert(all_targets, t[1])
            table.insert(tos, t[1])
            table.removeOne(tos, to.id)
            room:sortPlayersByAction(tos)
            room:sendLog({
              type = "#RfuyaoLiyeTargets",
              from = to.id,
              to = tos,
              toast = true,
            })
            to = room:getPlayerById(t[1])
          else
            to = player
          end
        else
          to = player
        end
      end
    end
    if table.find(tos, function (id)
      return not table.contains(TargetGroup:getRealTargets(use.tos), id)
    end) then
      room:sortPlayersByAction(all_targets)
      room:sortPlayersByAction(tos)
      for _, id in ipairs(TargetGroup:getRealTargets(use.tos)) do
        TargetGroup:removeTarget(use.tos, id)
      end
      if room:askForSkillInvoke(player, self.name, nil, "#rfenghou__liye-invoke") then
        for _, id in ipairs(all_targets) do
          TargetGroup:pushTargets(use.tos, id)
        end
        room:loseHp(player, 1, self.name)
      else
        for _, id in ipairs(tos) do
          TargetGroup:pushTargets(use.tos, id)
        end
      end
    end
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
}
local liye_targetmod = fk.CreateTargetModSkill{
  name = "#rfenghou__liye_targetmod",
  bypass_distances =  function(self, player, skill, card, to)
    return card and table.contains(card.skillNames, "rfenghou__liye")
  end,
}
liye:addRelatedSkill(liye_targetmod)]]--
local kuizhul = fk.CreateTriggerSkill{
  name = "rfenghou__kuizhul",
  anim_type = "control",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.to == Player.Start and not target.dead and target ~= player and
     player:canPindian(target)
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data, "#rfenghou__kuizhul-invoke::"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pindian = player:pindian({target}, self.name)
    local winner = pindian.results[target.id].winner
    if winner and not winner.dead then
      local choices = {"phase_draw", "phase_discard"}
      if pindian.fromCard:compareSuitWith(pindian.results[target.id].toCard) then
        table.insert(choices, "rfenghou__kuizhul3")
      end
      local choice = room:askForChoice(winner, choices, self.name, "#rfenghou__kuizhul-choice::"..target.id)
      if choice == "phase_draw" then
        data.to = Player.Draw
      elseif choice == "phase_discard" then
        data.to = Player.Discard
      elseif choice == "rfenghou__kuizhul3" then
        data.to = Player.Play
        if not target.dead and not target:hasSkill("luanji", true) then
          room:setPlayerMark(target, "rfenghou__kuizhul-phase", 1)
        end
      end
    end
  end,

  refresh_events = {fk.EventPhaseStart, fk.EventPhaseSkipped},
  can_refresh = function (self, event, target, player, data)
    if target == player and player:getMark("rfenghou__kuizhul-phase") > 0 then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      elseif event == fk.EventPhaseSkipped then
        return true
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "rfenghou__kuizhul-phase", 0)
    if event == fk.EventPhaseStart then
      if not player:hasSkill("luanji", true) then
        room:handleAddLoseSkills(player, "luanji", nil, true, false)
        room.logic:getCurrentEvent():findParent(GameEvent.Phase, true):addCleaner(function()
          room:handleAddLoseSkills(player, "-luanji")
        end)
      end
    end
  end,
}
liudai:addSkill(shuzhou)
--liudai:addSkill(liye)
liudai:addSkill(kuizhul)
Fk:loadTranslationTable{
  ["rfenghou__liudai"] = "刘岱",
  ["#rfenghou__liudai"] = "赴入辕哂",
  ["illustrator:rfenghou__liudai"] = "sier",
  ["designer:rfenghou__liudai"] = "白驹",
  ["cv:rfenghou__liudai"] = "白蓝海嗣",

  ["rfenghou__shuzhou"] = "束州",
  [":rfenghou__shuzhou"] = "准备阶段，你可以令其他角色依次选择是否交给你一张牌，然后直到你下次发动此技能，这些角色中选择交出牌和"..
  "不交出牌的角色相互造成的伤害+1。",
  ["rfenghou__liye"] = "立野",
  [":rfenghou__liye"] = "你可以将两张花色相同的牌当无距离限制的【杀】使用。当你以此法使用【杀】声明目标后，目标角色可以将目标转移给另一名"..
  "未成为过此次目标的其他角色，重复此流程。最后，你可以失去1点体力，指定所有此流程中被指定过的角色为目标。",
  ["rfenghou__kuizhul"] = "揆助",
  [":rfenghou__kuizhul"] = "其他角色的准备阶段，你可以与其拼点，赢的角色选择将此阶段改为摸牌或弃牌阶段，若两张拼点牌花色相同，也可以选择改为"..
  "拥有“乱击”的出牌阶段。",
  ["#rfenghou__shuzhou-invoke"] = "束州：你可以令所有其他角色选择是否交给你一张牌",
  ["#rfenghou__shuzhou-give"] = "束州：是否交给 %src 一张牌？",
  ["@rfenghou__shuzhou_give"] = "束州 交出牌",
  ["@rfenghou__shuzhou_nogive"] = "束州 未交出牌",
  ["#rfenghou__liye"] = "立野：将两张花色相同的牌当无距离限制的【杀】使用",
  ["#rfenghou__liye-choose"] = "立野：%src 对你使用【杀】，是否将目标转移给另一名角色？",
  ["#RfuyaoLiyeTargets"] = "%from 转移了目标，现在目标是 %to",
  ["#rfenghou__liye-invoke"] = "立野：是否失去1点体力，将目标改为所有被指定过的角色？",
  ["#rfenghou__kuizhul-invoke"] = "揆助：是否与 %dest 拼点？赢者可以将此准备阶段改为另一个阶段",
  ["#rfenghou__kuizhul-choice"] = "揆助：将 %dest 此准备阶段改为另一个阶段",
  ["rfenghou__kuizhul3"] = "出牌阶段，且拥有“乱击”",

  ["$rfenghou__shuzhou1"] = "持节北度，镇慰州郡，效祖先故事。",
  ["$rfenghou__shuzhou2"] = "拥兵专地、不尊汉辞，天下可复救乎？",
  ["$rfenghou__liye1"] = "纷乱至斯，德不在室，唯求诸于野。",
  ["$rfenghou__liye2"] = "保惠庶民、不悔鳏寡；小人之依，何处可求？",
  ["~rfenghou__liudai"] = "万人异心，一木难支……",
}


--FY009 伍琼种辑 by黄泉
local wuqiongchongji = General:new(extension, "rfenghou__wuqiongchongji", "han", 4)
local xiuchou = fk.CreateTriggerSkill{
  name = "rfenghou__xiuchou",
  anim_type = "offensive",
  events = {"fk.GeneralAppeared", fk.DamageCaused},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasShownSkill(self) then
      if event == "fk.GeneralAppeared" then
        return not player:isKongcheng()
      elseif event == fk.DamageCaused then
        return data.damage >= (data.to.hp + data.to.shield) and player:getMark("__hidden_general") == 0 and player:getMark("__hidden_deputy") == 0 
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == "fk.GeneralAppeared" then
      local n = #table.filter(player:getCardIds("h"), function (id)
        return not player:prohibitDiscard(id)
      end)
      room:setPlayerMark(player, self.name, n)
      player:throwAllCards("h")
      if player.dead then return end
      local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#rfenghou__xiuchou-choose", self.name, false)
      room:damage{
        from = player,
        to = room:getPlayerById(to[1]),
        damage = 1,
        skillName = self.name,
      }
    elseif event == fk.DamageCaused then
      DIY.EnterHidden(player)
    end
  end,
}
xiuchou.isHiddenSkill = true
--[[local renxie = fk.CreateActiveSkill{
  name = "rfenghou__renxie",
  anim_type = "drawcard",
  card_num = function ()
    local n = Self:getHandcardNum() - Self:getMark("rfenghou__xiuchou")
    if n > 0 then
      return n
    else
      return 0
    end
  end,
  target_num = 0,
  prompt = function (self)
    local n = Self:getMark(self.name)
    local n2 = Self:getHandcardNum() > Self:getMark("rfenghou__xiuchou") and 2 or 1
    if n ~= n2 then
      n = 0
    end
    return "#rfenghou__renxie"..n..":::"..Self:getMark("rfenghou__xiuchou")
  end,
  can_use = function(self, player)
    return player:getHandcardNum() ~= player:getMark("rfenghou__xiuchou")
  end,
  card_filter = function (self, to_select, selected)
    local n = Self:getHandcardNum() - Self:getMark("rfenghou__xiuchou")
    if n > 0 then
      return #selected < n and not Self:prohibitDiscard(to_select) and table.contains(Self:getCardIds("h"), to_select)
    else
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local status = player:getMark(self.name)
    if #effect.cards == 0 then
      player:drawCards(player:getMark("rfenghou__xiuchou") - player:getHandcardNum(), self.name)
      room:setPlayerMark(player, self.name, 1)
    else
      room:throwCard(effect.cards, self.name, player, player)
      room:setPlayerMark(player, self.name, 2)
    end
    if player.dead or status ~= player:getMark(self.name) then return end
    if status == 1 then
      room:loseHp(player, 1, self.name)
    else
      U.askForUseVirtualCard(room, player, "slash", nil, self.name, "#rfenghou__renxie-slash", true, true, false, true)
    end
  end,
}]]--
local renxie = fk.CreateActiveSkill{
  name = "rfenghou__renxie",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  prompt = function (self)
    local n = Self:getMark(self.name)
    --[[local n2 = Self:getHandcardNum() > Self:getMark("rfenghou__xiuchou") and 2 or 1
    if n ~= n2 then
      n = 0
    end]]--
    return "#rfenghou__renxie0:::"..Self:getMark("rfenghou__xiuchou")
  end,
  can_use = function(self, player)
    return player:getHandcardNum() < player:getMark("rfenghou__xiuchou")
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
      player:drawCards(player:getMark("rfenghou__xiuchou") - player:getHandcardNum(), self.name)
    if player.dead then return end
    if #player.room.logic:getEventsOfScope(GameEvent.Death, 1, function (e)
      return true
    end, Player.HistoryTurn) == 0 then
      room:loseHp(player, 1, self.name)
    end
  end,
}
wuqiongchongji:addSkill(xiuchou)
wuqiongchongji:addSkill(renxie)
Fk:loadTranslationTable{
  ["rfenghou__wuqiongchongji"] = "伍琼种辑",
  ["#rfenghou__wuqiongchongji"] = "白衣无顾",
  ["illustrator:rfenghou__wuqiongchongji"] = "食茸",
  ["designer:rfenghou__wuqiongchongji"] = "黄泉",
  ["cv:rfenghou__wuqiongchongji"] = "子瞻＆妙啊",

  ["rfenghou__xiuchou"] = "袖雠",
  [":rfenghou__xiuchou"] = "隐匿技，你登场后，你须弃置全部手牌，然后对一名角色造成1点伤害。当你对一名角色造成致命伤害时，"..
  "<a href='rfenghou__enterhidden'>进入隐匿状态</a>。",
  ["rfenghou__renxie"] = "衽血",
  --[[[":rfenghou__renxie"] = "出牌阶段，你可以将手牌数调整至X（X你为上次发动〖袖雠〗弃置牌数），若你连续发动此技能均为摸/弃置牌，你失去1点体力/"..
  "视为使用一张【杀】。",]]--
  [":rfenghou__renxie"] = "出牌阶段，你可以将手牌数摸至X（X你为上次发动〖袖雠〗弃置牌数），若本回合没有角色死亡，你失去1点体力。",
  ["#rfenghou__xiuchou-choose"] = "袖雠：对一名角色造成1点伤害",
  --["#rfenghou__renxie0"] = "衽血：将手牌数调整至%arg",
  ["#rfenghou__renxie0"] = "衽血：将手牌摸至%arg",
  ["#rfenghou__renxie1"] = "衽血：将手牌数调整至%arg，然后失去1点体力",
  ["#rfenghou__renxie2"] = "衽血：将手牌数调整至%arg，然后视为使用一张【杀】",
  ["#rfenghou__renxie-slash"] = "衽血：你可以视为使用一张【杀】",

  ["$rfenghou__xiuchou1"] = "今者同赴国难，义在必行！",
  ["$rfenghou__xiuchou2"] = "《诗》云：无言不酬、无德不报。此之谓也。",
  ["$rfenghou__renxie1"] = "顺道而动，天下为向；因民而虑，天下为斗！",
  ["$rfenghou__renxie2"] = "壮士除贼，不得不尔，吾等岂乐杀人？",
  ["~rfenghou__wuqiongchongji"] = "不能为国家除贼，乃天数也……",
}

--FY010 杨奉韩暹 by楚萱
local yangfenghanxian = General:new(extension, "rfenghou__yangfenghanxian", "han", 4)
local kouyong = fk.CreateTriggerSkill{
  name = "rfenghou__kouyong",
  anim_type = "control",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead and player:inMyAttackRange(target) and not target:isAllNude() and
      not (player:isProhibited(target, Fk:cloneCard("dismantlement")) and player:isProhibited(target, Fk:cloneCard("snatch")))
  end,
  on_cost = function(self, event, target, player, data)
    local choices = table.filter({"dismantlement", "snatch"}, function (name)
      return not player:isProhibited(target, Fk:cloneCard(name))
    end)
    table.insert(choices, "Cancel")
    local choice = player.room:askForChoice(player, choices, self.name,
      "#rfenghou__kouyong-invoke::"..target.id, false, {"dismantlement", "snatch", "Cancel"})
    if choice ~= "Cancel" then
      self.cost_data = {choice = choice}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = self.cost_data.choice
    local card = Fk:cloneCard(choice)
    card.skillName = self.name
    local use = {
      from = player.id,
      tos = {{ target.id }},
      card = card,
    }
    if choice == "dismantlement" then
      use.extra_data = use.extra_data or {}
      use.extra_data.rfenghou__kouyong = player.id
    end
    room:useCard(use)
    if choice == "dismantlement" and not player.dead then
      local cards = player:getTableMark("rfenghou__kouyong-tmp")
      room:setPlayerMark(player, "rfenghou__kouyong-tmp", 0)
      cards = table.filter(cards, function (id)
        local c = Fk:getCardById(id)
        return table.contains(room.discard_pile, id) and
          (player:canUseTo(c, target, {bypass_times = true}) or player:canUseTo(c, player, {bypass_times = true}))
      end)
      if #cards > 0 then
        local use2 = U.askForUseRealCard(room, player, cards, nil, self.name,
          "#rfenghou__kouyong-use::"..target.id,
          {
            expand_pile = cards,
            bypass_times = true,
            extraUse = true,
            exclusive_targets = {player.id, target.id},
          },
          true, true)
        if use2 then
          if #use2.tos == 0 then
            if use2.card.multiple_targets then
              use2.tos = {}
              for _, p in ipairs({player, target}) do
                if not player:isProhibited(p, use2.card) then
                  if use2.card.skill:modTargetFilter(p.id, {}, player, card, false) then
                    table.insert(use2.tos, {p.id})
                  end
                end
              end
            else
              use2.tos = {{player.id}}
            end
          end
          room:useCard(use2)
        end
      end
    elseif choice == "snatch" and not target.dead then
      target:drawCards(1, self.name)
    end
  end,
}
local kouyong_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__kouyong_delay",

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if not player.dead then
      local cards = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.skillName == "dismantlement_skill" then
          local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
          if use_event ~= nil then
            local use = use_event.data[1]
            if (use.extra_data or {}).rfenghou__kouyong == player.id then
              for _, info in ipairs(move.moveInfo) do
                if table.contains(player.room.discard_pile, info.cardId) then
                  table.insertIfNeed(cards, info.cardId)
                end
              end
            end
          end
        end
      end
      if #cards > 0 then
        cards = U.moveCardsHoldingAreaCheck(player.room, cards)
        if #cards > 0 then
          self.cost_data = cards
          return true
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "rfenghou__kouyong-tmp", self.cost_data)
  end,
}
local weiming = fk.CreateTriggerSkill{
  name = "rfenghou__weiming",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand then
          return table.every(player.room.alive_players, function (p)
            return player:getHandcardNum() >= p:getHandcardNum()
          end)
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
    local skill = "ol_ex__yaowu"
    if turn_event == nil or turn_event.data[1] ~= player then
      skill = "jiaozi"
    end
    if not player:hasSkill(skill, true) then
      room:setPlayerMark(player, "rfenghou__weiming_"..skill, 1)
      room:handleAddLoseSkills(player, skill, nil, true, false)
    elseif player:getMark("rfenghou__weiming_"..skill) > 0 and player:isWounded() --[[and
      table.every(room:getOtherPlayers(player), function (p)
        return p:getHandcardNum() < player:getHandcardNum()
      end)]]--
      then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    end
  end,

  refresh_events = {fk.SkillEffect},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("rfenghou__weiming_"..data.name) > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "rfenghou__weiming_"..data.name, 0)
    room:handleAddLoseSkills(player, "-"..data.name, nil, true, false)
  end,
}
kouyong:addRelatedSkill(kouyong_delay)
yangfenghanxian:addSkill(kouyong)
yangfenghanxian:addSkill(weiming)
yangfenghanxian:addRelatedSkill("ol_ex__yaowu")
yangfenghanxian:addRelatedSkill("jiaozi")
Fk:loadTranslationTable{
  ["rfenghou__yangfenghanxian"] = "杨奉韩暹",
  ["#rfenghou__yangfenghanxian"] = "权驱龙辇",
  ["illustrator:rfenghou__yangfenghanxian"] = "食茸",
  ["designer:rfenghou__yangfenghanxian"] = "楚萱",
  ["cv:rfenghou__yangfenghanxian"] = "KEVIN&妙啊",

  ["rfenghou__kouyong"] = "寇勇",
  [":rfenghou__kouyong"] = "当你攻击范围内的角色受到伤害后，你可以选择一项：1.视为对其使用一张【过河拆桥】，然后你可以对你或其使用"..
  "因此被弃置的牌；2.视为对其使用一张【顺手牵羊】，然后其摸一张牌。",
  ["rfenghou__weiming"] = "威命",
  [":rfenghou__weiming"] = "锁定技，当你的手牌数成为全场最多时，若此时为你的回合内/外，你获得〖耀武〗/〖骄恣〗至你发动之；"..
  "若你已有对应技能，则改为回复1点体力。",
  ["#rfenghou__kouyong-invoke"] = "寇勇：你可以视为对 %dest 使用【过河拆桥】或【顺手牵羊】",
  ["#rfenghou__kouyong-use"] = "寇勇：你可以对你或 %dest 使用被弃置的牌",

  ["$rfenghou__kouyong1"] = "蹂稼穑、夺妇女，勇力傍身，有何不可！",
  ["$rfenghou__kouyong2"] = "大将克敌，焚掠肆杀，士众自然用命。",
  ["$rfenghou__weiming1"] = "朝廷官爵威福，今操在谁手？",
  ["$rfenghou__weiming2"] = "汉皇承天威命，某家携之，亦可用！",
  ["$ol_ex__yaowu_rfenghou__yangfenghanxian"] = "陛下行幸，宵小岂敢窥视？",
  ["$jiaozi_rfenghou__yangfenghanxian"] = "护驾东归，元功于国，某必名垂竹帛！",
  ["~rfenghou__yangfenghanxian"] = "若有前知，何至于此……",
}

--FY014 刘渊 by yyuaN
local liuyuan = General:new(extension, "rfenghou__liuyuan", "han", 4)
-- 获取所有可用的隐匿技
local getHiddenSkill = function ()
  local ret = {}
  local whitelist_pack = {"ol"}
  -- 用于存放存在BUG的技能
  local blacklist_skill = {"efengqi__zongyi"}
  for g, general in pairs(Fk.generals) do
    if Fk:canUseGeneral(g)
    or (general.package and general.package.extensionName and
     (table.contains(whitelist_pack, general.package.extensionName) or table.contains(whitelist_pack, general.package.name))) then
      for _, skill in ipairs(general.skills) do
        if skill.isHiddenSkill and not table.contains(blacklist_skill, skill.name) then
          table.insert(ret, skill.name)
        end
      end
    end
  end
  return ret
end

local fuzhi = fk.CreateTriggerSkill{
  name = "rfenghou__fuzhi",
  anim_type = "special",
  events = {fk.TurnEnd},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and (player:getMark("rfenghou__fuzhi-turn") > 0 or
      table.contains(player:getTableMark("@[:]rfenghou__zhuozheng"), self.name))
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes(self.name, Player.HistoryRound) > 1 then
      room:loseHp(player, 1, self.name)
      if player.dead then return end
    end
    if player:getMark("__hidden_general") == 0 and player:getMark("__hidden_deputy") == 0 then
    DIY.EnterHidden(player)
    end
    if player.dead then return end
    room.tag[self.name] = room.tag[self.name] or {}
    if #room.tag[self.name] == 0 then
      room.tag[self.name] = getHiddenSkill()
    elseif player:usedSkillTimes(self.name, Player.HistoryGame) == 2 then
      table.insertIfNeed(room.tag[self.name], "rfenghou__pozhi")
    end
    local skills = table.filter(room.tag[self.name], function (name)
      return not player:hasSkill(name, true)
    end)
    if #skills > 0 then
      room:handleAddLoseSkills(player, table.random(skills), nil, true, false)
    end
  end,

  refresh_events = {"fk.GeneralAppeared"},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasShownSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "rfenghou__fuzhi-turn", 1)
  end,
}
fuzhi.isHiddenSkill = true
local zhuozheng = fk.CreateTriggerSkill{
  name = "rfenghou__zhuozheng",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Play then
      local choices = {"Cancel"}
      for _, skill in ipairs({"rfenghou__fuzhi", "rfenghou__zhuozheng", "rfenghou__zuhe", "rfenghou__pozhi"}) do
        if player:hasSkill(skill, true) and not table.contains(player:getTableMark("@[:]rfenghou__zhuozheng"), skill) then
          table.insert(choices, skill)
        end
      end
      for _, skill in ipairs(player.player_skills) do
        if skill.isHiddenSkill and not table.contains(player:getTableMark("@[:]rfenghou__zhuozheng"), skill.name) then
          table.insertIfNeed(choices, skill.name)
        end
      end
      if #choices > 0 then
        self.cost_data = choices
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local choice = player.room:askForChoice(player, self.cost_data, self.name, "#rfenghou__zhuozheng-choice", true)
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:addTableMark(player, "@[:]rfenghou__zhuozheng", self.cost_data)
  end,
}
local zhuozheng_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__zhuozheng_delay",
  mute = true,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target.phase == Player.Play and player:getMark("@[:]rfenghou__zhuozheng") ~= 0 and
      target.hp == player.hp and target:getHandcardNum() == player:getHandcardNum() then
      local yes = false
      player.room:setPlayerMark(player, "rfenghou__zhuozheng-tmp", 1)
      for _, s in ipairs(player:getMark("@[:]rfenghou__zhuozheng")) do
        local skill = Fk.skills[s]
        if player:hasSkill(s) and skill:triggerable(skill.events[1], target, player, data) then
          yes = true
        end
      end
      player.room:setPlayerMark(player, "rfenghou__zhuozheng-tmp", 0)
      return yes
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "rfenghou__zhuozheng-tmp", 1)
    local skill_names = table.simpleClone(table.filter(player:getMark("@[:]rfenghou__zhuozheng"), function (s)
      local skill = Fk.skills[s]
      if player:hasSkill(s) and skill:triggerable(skill.events[1], target, player, data) then
        return true
      end
    end))
    room:setPlayerMark(player, "rfenghou__zhuozheng-tmp", 0)
    while not player.dead and #skill_names > 0 do
      local skill_name = room:askForChoice(player, skill_names, "trigger", "#choose-trigger")
      table.removeOne(skill_names, skill_name)
      local skill = Fk.skills[skill_name]
      skill:trigger(skill.events[1], target, player, data)
      room:setPlayerMark(player, "rfenghou__zhuozheng-tmp", 1)
      skill_names = table.filter(skill_names, function (s)
        return player:hasSkill(s)
      end)
      room:setPlayerMark(player, "rfenghou__zhuozheng-tmp", 0)
    end
  end,
}
local zhuozheng_invalidity = fk.CreateInvaliditySkill {
  name = "#rfenghou__zhuozheng_invalidity",
  invalidity_func = function(self, from, skill)
    if from:getMark("@[:]rfenghou__zhuozheng") ~= 0 and from:getMark("rfenghou__zhuozheng-tmp") == 0 then
      return table.contains(from:getMark("@[:]rfenghou__zhuozheng"), skill.name)
    end
  end
}
local zuhe = fk.CreateTriggerSkill{
  name = "rfenghou__zuhe$",
  anim_type = "drawcard",
  events = {fk.HpRecover},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and not player:isWounded() then
      local surnames = {}
      for _, p in ipairs(player.room.alive_players) do
        if p.kingdom == "han" then
          local name = Fk:translate(p.general, "zh_CN")
          table.insertIfNeed(surnames, name[1])
          if name:len() > 3 then
            table.insertIfNeed(surnames, name[3])
          end
        end
      end
      local n = #surnames - player:getHandcardNum()
      if n > 0 then
        self.cost_data = n
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(self.cost_data, self.name)
  end,
}
local pozhi = fk.CreateTriggerSkill{
  name = "rfenghou__pozhi",
  anim_type = "offensive",
  events = {"fk.GeneralAppeared"},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasShownSkill(self, true)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choices = {}
    for _, skill in ipairs(player.player_skills) do
      if skill.isHiddenSkill then
        table.insert(choices, skill.name)
      end
    end
    local prompt = "#rfenghou__pozhi-choice"
    if player:usedSkillTimes(self.name, Player.HistoryGame) == 1 and table.contains(choices, "rfenghou__fuzhi") then
      prompt = "#rfenghou__pozhi1-choice"
    end
    local choice = room:askForChoices(player, choices, 1, #choices, self.name, prompt, false, true)
    if prompt == "#rfenghou__pozhi1-choice" then
      table.insertIfNeed(choice, "rfenghou__fuzhi")
    end
    room:handleAddLoseSkills(player, "-"..table.concat(choice, "|-"), nil, true, false)
    if player.dead then return end
    local total = #choice
    --[[while total > 0 do
      room:setPlayerMark(player, "rfenghou__pozhi-tmp", total)
      local _, dat = room:askForUseActiveSkill(player, "rfenghou__pozhi_active",
        "#rfenghou__pozhi-num:::"..total, false)
      local to = room:getPlayerById(dat.targets[1])
      room:addPlayerMark(to, "@rfenghou__pozhi_count", dat.interaction)
      total = total - dat.interaction
    end
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:getMark("@rfenghou__pozhi_count") > 0 then
        room:damage{
          from = player,
          to = p,
          damage = p:getMark("@rfenghou__pozhi_count"),
          skillName = self.name,
        }
        room:setPlayerMark(p, "@rfenghou__pozhi_count", 0)
      end
    end]]--
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, total,
      "#rfenghou__pozhi-damage:::"..total, self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      for _, id in ipairs(tos) do
        local p = room:getPlayerById(id)
        if not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = self.name,
          }
        end
      end
    end
  end,
}
local pozhi_active = fk.CreateActiveSkill{
  name = "rfenghou__pozhi_active",
  card_num = 0,
  target_num = 1,
  interaction = function()
    return UI.Spin {
      from = 1,
      to = Self:getMark("rfenghou__pozhi-tmp"),
    }
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected)
    return #selected == 0
  end,
}
pozhi.isHiddenSkill = true
--Fk:addSkill(pozhi_active)
zhuozheng:addRelatedSkill(zhuozheng_delay)
zhuozheng:addRelatedSkill(zhuozheng_invalidity)
liuyuan:addSkill(fuzhi)
liuyuan:addSkill(zhuozheng)
liuyuan:addSkill(zuhe)
liuyuan:addRelatedSkill(pozhi)
Fk:loadTranslationTable{
  ["rfenghou__liuyuan"] = "刘渊",
  ["#rfenghou__liuyuan"] = "思穹志海",
  ["illustrator:rfenghou__liuyuan"] = "sier",
  ["designer:rfenghou__liuyuan"] = "yyuaN",
  ["cv:rfenghou__liuyuan"] = "KEVIN",

  ["rfenghou__fuzhi"] = "缚枝",
  [":rfenghou__fuzhi"] = "隐匿技，你登场的回合结束时，<a href='enter_hidden_href'>进入隐匿状态</a>并随机获得一个隐匿技"..
  "（若不为本轮首次发动此技能，你先失去1点体力），然后本局游戏隐匿技能库中加入一个特殊隐匿技〖破桎〗。",
  ["rfenghou__zhuozheng"] = "琢政",
  [":rfenghou__zhuozheng"] = "出牌阶段开始时，你可以将此武将牌上的一个技能或你拥有的一个隐匿技的时机修改为：体力值和手牌数均与你相等的角色"..
  "出牌阶段结束时。<br>（点击“琢政”标记可以查看修改过的技能）",
  ["rfenghou__zuhe"] = "族合",
  [":rfenghou__zuhe"] = "主公技，当你回复体力至体力上限后，你可以将手牌摸至场上汉势力角色姓氏数。",
  ["rfenghou__pozhi"] = "破桎",
  [":rfenghou__pozhi"] = "隐匿技，你登场时，失去任意个隐匿技（若为首次发动此技能，则必须失去〖缚枝〗），然后对至多等量的角色各造成1点伤害。",
  ["#rfenghou__zhuozheng-choice"] = "琢政：你可以修改一个技能的时机为“与你体力值和手牌数均相等的角色出牌阶段结束时”",
  ["@[:]rfenghou__zhuozheng"] = "琢政",
  --["#rfenghou__pozhi-choice"] = "破桎：请选择失去任意个隐匿技，然后对所有角色分配等量的伤害",
  --["#rfenghou__pozhi1-choice"] = "破桎：请选择失去任意个隐匿技（本次必须失去“缚枝”），然后对所有角色分配等量的伤害",
  ["#rfenghou__pozhi-choice"] = "破桎：请选择失去任意个隐匿技，然后对等量名角色造成伤害",
  ["#rfenghou__pozhi1-choice"] = "破桎：请选择失去任意个隐匿技（本次必须失去“缚枝”），然后对等量名角色造成伤害",
  --["rfenghou__pozhi_active"] = "破桎",
  --["#rfenghou__pozhi-num"] = "破桎：分配造成伤害点数（还剩%arg点）！",
  --["@rfenghou__pozhi_count"] = "伤害值",
  ["#rfenghou__pozhi-damage"] = "破桎：对至多%arg名角色各造成1点伤害",

  ["$rfenghou__fuzhi1"] = "身是吞舟之鱼，岂可游于枝流？",
  ["$rfenghou__fuzhi2"] = "我有大翼垂天，当负长风万里。",
  ["$rfenghou__zhuozheng1"] = "政宽则民慢、猛则民残，为政当琢以和。",
  ["$rfenghou__zhuozheng2"] = "布政优优、百禄是遒；柔远能迩，以定我王。",
  ["$rfenghou__zuhe1"] = "绍三祖之业，重升汉道，卒以刷耻！",
  ["$rfenghou__zuhe2"] = "国统濒绝，宗庙之不血食，四十年于兹矣！",
  ["$rfenghou__pozhi1"] = "海压竹节低复举，风吹山棱晦转明！",
  ["$rfenghou__pozhi2"] = "富有四海而不恣睢，天下与桎梏何异？",
  ["~rfenghou__liuyuan"] = "刘氏种，尚可复遗乎？",
}

--FY015 吕玲绮 by三秋
local lvlingqi = General:new(extension, "rfenghou__lvlingqi", "han", 4, 4, General.Female)
local xiwei = fk.CreateTriggerSkill{
  name = "rfenghou__xiwei",
  anim_type = "control",
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.num > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__xiwei-invoke:::"..data.num)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = data.num
    data.num = 0
    for i = 1, n, 1 do
      if player.dead then return end
      local targets = table.map(table.filter(room.alive_players, function(p)
        return p:isWounded() and (not p:isKongcheng() or table.find(room.alive_players, function(to)
          return p:canMoveCardsInBoardTo(to, "e")
        end))
      end), Util.IdMapper)
      if #targets == 0 then
        local cards = table.filter(room.draw_pile, function (id)
          local card = Fk:getCardById(id)
          return card.is_damage_card and not card.multiple_targets
        end)
        if #cards > 0 then
          room:moveCardTo(table.random(cards), Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, false, player.id)
        end
      else
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#rfenghou__xiwei-choose:::"..i..":"..n, self.name, true)
        if #to > 0 then
          to = room:getPlayerById(to[1])
          local choices = {}
          if not to:isKongcheng() then
            table.insert(choices, "rfenghou__xiwei_hand")
          end
          targets = table.filter(room.alive_players, function(p)
            return to:canMoveCardsInBoardTo(p, "e")
          end)
          if #targets > 0 then
            table.insert(choices, "rfenghou__xiwei_board")
          end
          if #choices == 0 then return end
          local choice = room:askForChoice(player, choices, self.name)
          if choice == "rfenghou__xiwei_hand" then
            targets = room:getOtherPlayers(to)
          end
          local t = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
            "#rfenghou__xiwei-move::"..to.id, self.name, false)
          if choice == "rfenghou__xiwei_hand" then
            local cid = room:askForCardChosen(player, to, "h", self.name)
            room:moveCardTo(cid, Card.PlayerHand, room:getPlayerById(t[1]), fk.ReasonJustMove, self.name, nil, false, player.id)
          else
            room:askForMoveCardInBoard(player, to, room:getPlayerById(t[1]), self.name, "e", to, {})
          end
        else
          local cards = table.filter(room.draw_pile, function (id)
            local card = Fk:getCardById(id)
            return card.is_damage_card and not card.multiple_targets
          end)
          if #cards > 0 then
            room:moveCardTo(table.random(cards), Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, false, player.id)
          end
        end
      end
    end
    if not player.dead and not player:hasSkill("wushuang", true) then
      local phase_event = room.logic:getCurrentEvent():findParent(GameEvent.Phase)
      if phase_event == nil then return end
      local types = {}
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.to == player.id and move.toArea == Card.PlayerHand then
            for _, info in ipairs(move.moveInfo) do
              table.insertIfNeed(types, Fk:getCardById(info.cardId).type)
            end
          end
        end
      end, Player.HistoryPhase)
      if #types == 1 then
        room:handleAddLoseSkills(player, "wushuang", nil, true, false)
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(player, "-wushuang")
        end)
      end
    end
  end,
}
lvlingqi:addSkill(xiwei)
lvlingqi:addRelatedSkill("wushuang")
Fk:loadTranslationTable{
  ["rfenghou__lvlingqi"] = "吕玲绮",
  ["#rfenghou__lvlingqi"] = "翻戟困獒",
  ["illustrator:rfenghou__lvlingqi"] = "祭祀",
  ["designer:rfenghou__lvlingqi"] = "三秋",

  ["rfenghou__xiwei"] = "袭围",
  [":rfenghou__xiwei"] = "当你摸牌时，你可以放弃摸牌，改为选择等量次：1.移动一名已受伤角色的一张牌；2.从牌堆随机获得一张单目标伤害牌。"..
  "然后若你此阶段获得的牌均为同一类别，你视为拥有〖无双〗直到回合结束。",
  ["#rfenghou__xiwei-invoke"] = "袭围：你即将摸%arg张牌，是否放弃摸牌，改为进行等量次选择？",
  ["#rfenghou__xiwei-choose"] = "袭围：选择一名角色移动其一张牌，或点“取消”获得一张单目标伤害牌（第%arg次，共%arg2次）",
  ["#rfenghou__xiwei-move"] = "袭围：选择一名角色，将 %dest 的一张牌移至目标角色",
  ["rfenghou__xiwei_hand"] = "移动手牌",
  ["rfenghou__xiwei_board"] = "移动装备",
}

local haopu = General:new(extension, "rfenghou__haopu", "han", 4)
local jicheng = fk.CreateActiveSkill{
  name = "rfenghou__jicheng",
  anim_type = "control",
  prompt = "#rfenghou__jicheng",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if player.dead then return end
    if pindian.results[target.id].winner ~= player then
      local n = 0
      if pindian.fromCard.color == Card.Red then
        n = n + 1
      end
      if pindian.results[target.id].toCard.color == Card.Red then
        n = n + 1
      end
      if n > 0 then
        room:addPlayerMark(player, MarkEnum.MinusMaxCards.."-turn", n)
        room:broadcastProperty(player, "MaxCards")
      end
    end
    local choices = {"rfenghou__jicheng3"}
    local n = player:getHandcardNum() - player:getMaxCards()
    if n == -2 then
      table.insert(choices, "draw2")
    elseif n == 1 then
      for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:cloneCard("duel")
        card:addSubcard(id)
        card.skillName = self.name
        if table.find(room:getOtherPlayers(player), function (p)
          return player:canUseTo(card, p)
        end) then
          table.insert(choices, "rfenghou__jicheng2")
          break
        end
      end
    elseif n == 0 and #player:getCardIds("e") > 0 then
      for _, id in ipairs(player:getCardIds("e")) do
        local card = Fk:cloneCard("duel")
        card:addSubcard(id)
        card.skillName = self.name
        if table.find(room:getOtherPlayers(player), function (p)
          return player:canUseTo(card, p)
        end) then
          table.insert(choices, "rfenghou__jicheng2")
          break
        end
      end
    end
    local choice = room:askForChoice(player, choices, self.name,
      "#rfenghou__jicheng-choice:::"..player:getMaxCards(), nil, {"draw2", "rfenghou__jicheng2", "rfenghou__jicheng3"})
    if choice == "draw2" then
      player:drawCards(2, self.name)
    elseif choice == "rfenghou__jicheng2" then
      local prompt = "#rfenghou__jicheng-hand"
      if n == 0 then
        prompt = "#rfenghou__jicheng-equip"
      end
      local success, dat = room:askForUseActiveSkill(player, "rfenghou__jicheng_viewas", prompt, false, nil, true)
      if success then
        local card = Fk:cloneCard("duel")
        card.skillName = self.name
        card:addSubcards(dat.cards)
        room:useCard{
          from = player.id,
          tos = table.map(dat.targets, function(id) return {id} end),
          card = card,
        }
      end
    elseif choice == "rfenghou__jicheng3" then
      if n < 0 then
        player:drawCards(-n, self.name)
      elseif n > 0 then
        room:askForDiscard(player, n, n, false, self.name, false)
      end
      room:endTurn()
    end
  end,
}
local jicheng_viewas = fk.CreateViewAsSkill{
  name = "rfenghou__jicheng_viewas",
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      if Self:getHandcardNum() == Self:getMaxCards() then
        return table.contains(Self:getCardIds("e"), to_select)
      else
        return table.contains(Self:getCardIds("h"), to_select)
      end
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("duel")
    card:addSubcard(cards[1])
    card.skillName = "rfenghou__jicheng"
    return card
  end,
}
Fk:addSkill(jicheng_viewas)
haopu:addSkill(jicheng)
Fk:loadTranslationTable{
  ["rfenghou__haopu"] = "郝普",
  ["#rfenghou__haopu"] = "悬壑把晖",
  ["illustrator:rfenghou__haopu"] = "君桓文化",
  ["designer:rfenghou__haopu"] = "yyuaN",

  ["rfenghou__jicheng"] = "岌城",
  [":rfenghou__jicheng"] = "出牌阶段，你可以拼点，若你没赢，本回合手牌上限-X（X为红色拼点牌数）。然后你执行一项效果以使你手牌数等于"..
  "手牌上限：1.摸两张牌；2.将一张牌当【决斗】使用；3.调整手牌至手牌上限，结束回合。",
  ["#rfenghou__jicheng"] = "岌城：你可以拼点，然后执行一项效果以使你的手牌数等于手牌上限",
  ["#rfenghou__jicheng-choice"] = "岌城：请选择执行一项以令手牌数等于手牌上限（当前手牌上限为%arg）",  --FIXME: 万恶的手牌上限UI
  ["rfenghou__jicheng2"] = "将一张牌当【决斗】使用",
  ["rfenghou__jicheng3"] = "调整手牌至手牌上限，结束回合",
  ["rfenghou__jicheng_viewas"] = "岌城",
  ["#rfenghou__jicheng-hand"] = "岌城：请将一张手牌当【决斗】使用",
  ["#rfenghou__jicheng-equip"] = "岌城：请将装备区一张牌当【决斗】使用",

  ["$rfenghou__jicheng1"] = "吾闻世间有忠义，今欲为之。",
  ["$rfenghou__jicheng2"] = "吴虽兵临三郡，普宁死不降。",
  ["~rfenghou__haopu"] = "徒做奔臣，死无其所。",
}


local mengda = General:new(extension, "rfenghou__mengda", "han", 4)
local qiedai = fk.CreateViewAsSkill{
  name = "rfenghou__qiedai",
  anim_type = "defensive",
  pattern = "jink",
  prompt = "#rfenghou__qiedai",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard("jink")
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return #p:getEquipments(Card.SubtypeArmor) > 0
    end)
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
      "#rfenghou__qiedai-choose", self.name, false)
    to = room:getPlayerById(to[1])
    if #to:getEquipments(Card.SubtypeArmor) == 1 then
      use.card:addSubcard(to:getEquipments(Card.SubtypeArmor)[1])
    elseif #to:getEquipments(Card.SubtypeArmor) > 1 then
      local card = U.askforChooseCardsAndChoice(player, to:getEquipments(Card.SubtypeArmor), {"OK"}, self.name,
        "#rfenghou__qiedai-jink::"..to.id)
      use.card:addSubcard(card[1])
    else
      return ""
    end
  end,
  enabled_at_response = function (self, player, response)
    return not response and table.find(Fk:currentRoom().alive_players, function (p)
      return #p:getEquipments(Card.SubtypeArmor) > 0
    end)
  end,
}
local qiedai_trigger = fk.CreateTriggerSkill{
  name = "#rfenghou__qiedai_trigger",
  anim_type = "drawcard",
  main_skill = qiedai,
  events = {fk.AskForCardUse},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(qiedai) and #target:getCardIds("e") == 0 and not player:isKongcheng() and
      (data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none")))
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "rfenghou__qiedai_active", "#rfenghou__qiedai-recast", true)
    if success and dat then
      self.cost_data = {cards = dat.cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:recastCard(self.cost_data.cards, player, "rfenghou__qiedai")
  end,
}
local qiedai_active = fk.CreateActiveSkill{
  name = "rfenghou__qiedai_active",
  min_card_num = 1,
  target_num = 0,
  card_filter = Util.TrueFunc,
  feasible = function (self, selected, selected_cards)
    return #selected_cards > 0 and
      table.find(selected_cards, function (id)
        return Fk:getCardById(id).trueName == "jink"
      end)
  end,
}
local qiedaim = fk.CreateTriggerSkill{
  name = "rfenghou__qiedaim",
  anim_type = "drawcard",
  events = {fk.AskForPeaches},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.who ~= player.id and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__qiedaim-invoke::"..data.who)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.simpleClone(player:getCardIds("h"))
    player:showCards(cards)
    if player.dead then return end
    if table.find(cards, function (id)
      return Fk:getCardById(id).trueName == "peach"
    end) then
      player:drawCards(2, self.name)
    elseif #room:askForDiscard(player, 2, 2, true, self.name, true, nil, "#rfenghou__qiedaim-discard") > 0 then
      if player.dead then return end
      local card = room:getCardsFromPileByRule("peach")
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
      end
    end
    if not player.dead then
      room:setPlayerMark(player, "rfenghou__qiedaim-phase", room.logic:getCurrentEvent().id)
    end
  end,

  refresh_events = {fk.AskForPeaches, fk.AskForPeachesDone},
  can_refresh = function (self, event, target, player, data)  --不想用HandleAskForPlayCard
    return target ~= player and player:getMark("rfenghou__qiedaim-phase") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "rfenghou__qiedaim-phase", 0)
  end,
}
local qiedaim_prohibit = fk.CreateProhibitSkill{
  name = "#rfenghou__qiedaim_prohibit",
  prohibit_use = function(self, player, card)
    return card and card.name == "peach" and player:getMark("rfenghou__qiedaim-phase") ~= 0
  end,
}
Fk:addSkill(qiedai_active)
qiedai:addRelatedSkill(qiedai_trigger)
qiedaim:addRelatedSkill(qiedaim_prohibit)
mengda:addSkill(qiedai)
mengda:addSkill(qiedaim)
Fk:loadTranslationTable{
  ["rfenghou__mengda"] = "孟达",
  ["#rfenghou__mengda"] = "如此反复",
  ["illustrator:rfenghou__mengda"] = "匠人绘",
  ["designer:rfenghou__mengda"] = "廷玉",

  ["rfenghou__qiedai"] = "且待",
  [":rfenghou__qiedai"] = "你可以将场上的防具牌当【闪】使用；装备区内没有牌的角色需使用【闪】时，你可以重铸任意张牌（需包含【闪】）。",
  ["rfenghou__qiedaim"] = "切怠",
  [":rfenghou__qiedaim"] = "当其他角色濒死结算求桃流程询问至你时，你可以改为展示所有手牌，若其中：有【桃】，你摸两张牌；没有【桃】，"..
  "你可以弃置两张牌，获得一张【桃】。",
  ["#rfenghou__qiedai"] = "且待：你可以将场上的防具牌当【闪】使用（点“确定”，然后选择有防具牌的角色）",
  ["#rfenghou__qiedai-choose"] = "且待：选择一名角色，将其防具当【闪】使用",
  ["#rfenghou__qiedai-jink"] = "且待：选择 %dest 的一张防具，将之当【闪】使用",
  ["#rfenghou__qiedai_trigger"] = "且待",
  ["rfenghou__qiedai_active"] = "且待",
  ["#rfenghou__qiedai-recast"] = "且待：你可以重铸任意张牌（需包含【闪】）",
  ["#rfenghou__qiedaim-invoke"] = "切怠：%dest 向你求桃，是否展示所有手牌见死不救？",
  ["#rfenghou__qiedaim-discard"] = "切怠：是否弃置两张牌，获得一张【桃】？",

  ["$rfenghou__qiedai1"] = "达本蜀之降将，幸得君上重为卿相。",
  ["$rfenghou__qiedai2"] = "刚正易折，委屈得全，我自玲珑八面。",
  ["$rfenghou__qiedaim1"] = "蝼蚁尚且偷生，况我大将军乎。",
  ["$rfenghou__qiedaim2"] = "为保身家性命，做奔臣又如何？",
  ["~rfenghou__mengda"] = "司马公，吾等愿降！",
}

local xiangchong = General:new(extension, "rfenghou__xiangchong", "han", 4)
local suzhen = fk.CreateActiveSkill{
  name = "rfenghou__suzhen",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#rfenghou__suzhen",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])

    local use = U.askForPlayCard(room, target, nil, ".|.|.|.|.|basic", self.name, "#rfenghou__suzhen-use",
      {bypass_times = true, extraUse = true})
    if use then
      if not target.dead then
        target:drawCards(1, self.name)
      end
    else
      use = U.askForPlayCard(room, player, nil, ".|.|.|.|.|basic", self.name, "#rfenghou__suzhen2-use::"..target.id,
        {bypass_times = true, extraUse = true})
      if use and not player.dead and not target.dead and not target:isNude() and
        room:askForSkillInvoke(player, self.name, nil, "#rfenghou__suzhen-invoke::"..target.id) then
        room:doIndicate(player.id, {target.id})
        local card = room:askForCardChosen(player, target, "he", self.name, "#rfenghou__suzhen-discard::"..target.id)
        room:throwCard(card, self.name, target, player)
      end
    end

    local yes = true
    if not target.dead and #target:getCardIds("e") > 0 then
      local card = room:askForCard(target, 1, 1, true, self.name, true, ".|.|.|equip", "#rfenghou__suzhen-equip")
      if #card > 0 then
        yes = false
        room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonJustMove, self.name, nil, true, target.id)
        if not target.dead then
          target:drawCards(1, self.name)
        end
      end
    end
    if yes and not player.dead and #player:getCardIds("e") > 0 then
      local card = room:askForCard(player, 1, 1, true, self.name, true, ".|.|.|equip", "#rfenghou__suzhen2-equip::"..target.id)
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
        if not player.dead and not target.dead and not target:isNude() and
          room:askForSkillInvoke(player, self.name, nil, "#rfenghou__suzhen-invoke::"..target.id) then
          room:doIndicate(player.id, {target.id})
          card = room:askForCardChosen(player, target, "he", self.name, "#rfenghou__suzhen-discard::"..target.id)
          room:throwCard(card, self.name, target, player)
        end
      end
    end

    yes = true
    if not target.dead and not target:isKongcheng() then
      local card = room:askForCard(target, 1, 1, false, self.name, true, ".|.|.|.|.|trick", "#rfenghou__suzhen-recast")
      if #card > 0 then
        yes = false
        room:recastCard(card, target, self.name)
        if not target.dead then
          target:drawCards(1, self.name)
        end
      end
    end
    if yes and not player.dead and not player:isKongcheng() then
      local card = room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|.|.|trick", "#rfenghou__suzhen2-recast::"..target.id)
      if #card > 0 then
        room:recastCard(card, player, self.name)
        if not player.dead and not target.dead and not target:isNude() and
          room:askForSkillInvoke(player, self.name, nil, "#rfenghou__suzhen-invoke::"..target.id) then
          room:doIndicate(player.id, {target.id})
          card = room:askForCardChosen(player, target, "he", self.name, "#rfenghou__suzhen-discard::"..target.id)
          room:throwCard(card, self.name, target, player)
        end
      end
    end
  end,
}
xiangchong:addSkill(suzhen)
Fk:loadTranslationTable{
  ["rfenghou__xiangchong"] = "向宠",
  ["#rfenghou__xiangchong"] = "能",
  ["illustrator:rfenghou__xiangchong"] = "凝聚永恒",
  ["designer:rfenghou__xiangchong"] = "CYC",

  ["rfenghou__suzhen"] = "肃阵",
  [":rfenghou__suzhen"] = "出牌阶段限一次，你可以令一名角色依次选择是否执行：1.使用一张基本牌；2.收回装备区内一张牌；3.重铸一张锦囊牌。"..
  "其每执行一项，摸一张牌；每拒绝一项，你可以执行之，若如此做，你可以弃置其一张牌。",
  ["#rfenghou__suzhen"] = "肃阵：令一名角色依次执行选项，其每执行一项摸一张牌",
  ["#rfenghou__suzhen-use"] = "肃阵：你可以使用一张基本牌，摸一张牌",
  ["#rfenghou__suzhen2-use"] = "肃阵：你可以使用一张基本牌，然后可以弃置 %dest 一张牌",
  ["#rfenghou__suzhen-equip"] = "肃阵：你可以收回装备区一张牌，摸一张牌",
  ["#rfenghou__suzhen2-equip"] = "肃阵：你可以收回装备区一张牌，然后可以弃置 %dest 一张牌",
  ["#rfenghou__suzhen-recast"] = "肃阵：你可以重铸一张锦囊牌，摸一张牌",
  ["#rfenghou__suzhen2-recast"] = "肃阵：你可以重铸一张锦囊牌，然后可以弃置 %dest 一张牌",
  ["#rfenghou__suzhen-invoke"] = "肃阵：是否弃置 %dest 一张牌？",
  ["#rfenghou__suzhen-discard"] = "肃阵：弃置 %dest 一张牌",

  ["$rfenghou__suzhen1"] = "行阵和睦，方可优劣得所。",
  ["$rfenghou__suzhen2"] = "识时达务，才可上和下睦。",
  ["~rfenghou__xiangchong"] = "蛮夷怀异，战乱难平……",
}

local xiahoushi = General:new(extension, "rfenghou__xiahoushi", "han", 3, 3, General.Female)

local rfenghou__qiaoshi = fk.CreateTriggerSkill{
  name = "rfenghou__qiaoshi",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:isKongcheng() then return false end
    local names, card_ids, toProcess = {}, {}, {}
    for _, id in ipairs(player:getCardIds("h")) do
      local c = Fk:getCardById(id)
      if c.type ~= Card.TypeBasic then return false end
      table.insertIfNeed(names, c.name)
    end
    local room = player.room
    local current_event = room.logic:getCurrentEvent()
    local parent_event = current_event.parent
    if parent_event ~= nil then
      -- 用于查找因使用或打出等进入处理区后才进入弃牌堆的牌
      parent_event:searchEvents(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.Processing and move.from and move.from ~= player.id then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
                table.insert(toProcess, info.cardId)
              end
            end
          end
        end
      end, current_event)
    end
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        if move.from ~= player.id then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip)
              or (info.fromArea == Card.Processing and table.contains(toProcess, info.cardId)) then
              local c = Fk:getCardById(info.cardId)
              if c.type == Card.TypeBasic and not table.contains(names, c.name) then
                table.insert(card_ids, info.cardId)
              end
            end
          end
        end
      end
    end
    local record = player:getTableMark("rfenghou__qiaoshi-turn") -- 记录已经拿过的牌牌名
    card_ids = table.filter(card_ids, function(id)
      return room:getCardArea(id) == Card.DiscardPile and not table.contains(record, Fk:getCardById(id).name)
    end)
    if #card_ids > 0 then
      self.cost_data = {cards = card_ids}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.simpleClone(self.cost_data.cards)
    player:showCards(player:getCardIds("h"))
    local get, cardsMap = {}, {}
    for _, id in ipairs(cards) do
      local name = Fk:getCardById(id).trueName
      if cardsMap[name] == nil then
        cardsMap[name] = {id}
      else
        table.insert(cardsMap[name], id)
      end
    end
    for name, ids in pairs(cardsMap) do
      room:addTableMark(player, "rfenghou__qiaoshi-turn", name)
      if #ids == 1 then
        table.insert(get, ids[1])
      else
        table.insert(get, room:askForCardChosen(player, player, { card_data = { { name, ids } } }, self.name, "#rfenghou__qiaoshi-card"))
      end
    end
    room:obtainCard(player, get, true, fk.ReasonJustMove, player.id, self.name)
  end,
}
xiahoushi:addSkill(rfenghou__qiaoshi)

local rfenghou__yanyu = fk.CreateActiveSkill{
  name = "rfenghou__yanyu",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#rfenghou__yanyu",
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and #selected_cards == 1 and to_select ~= Self.id and not
    Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local lastCard, lastOne, num = effect.cards[1], player, Fk:getCardById(effect.cards[1]).number
    room:recastCard(effect.cards, player, self.name)
    local to = room:getPlayerById(effect.tos[1])
    while true do
      local temp = lastOne == player and to or player
      if temp.dead or temp:isNude() then break end
      lastOne = temp
      local cards = room:askForCard(lastOne, 1, 1, true, self.name, false, ".", "#rfenghou__yanyu-card:::"..num)
      lastCard = cards[1]
      local tempNum = num
      num = Fk:getCardById(lastCard).number
      room:recastCard(cards, lastOne, self.name)
      if num >= tempNum then break end
    end
    if Fk:getCardById(lastCard).suit == Card.Heart and not lastOne.dead then
      room:recover { num = 1, skillName = self.name, who = lastOne, recoverBy = player }
    end
  end,
}
xiahoushi:addSkill(rfenghou__yanyu)

Fk:loadTranslationTable{
  ["rfenghou__xiahoushi"] = "夏侯氏",
  ["#rfenghou__xiahoushi"] = "",
  ["illustrator:rfenghou__xiahoushi"] = "鬼sa",
  ["designer:rfenghou__xiahoushi"] = "柠檬",

  ["rfenghou__qiaoshi"] = "樵拾",
  [":rfenghou__qiaoshi"] = "每回合每牌名限一次，其他角色的基本牌进入弃牌堆时，你可以展示均为基本牌且与之牌名不同的所有手牌，获得之。",
  ["#rfenghou__qiaoshi-card"] = "樵拾：选择你要获得的牌！",

  ["rfenghou__yanyu"] = "燕语",
  [":rfenghou__yanyu"] = "出牌阶段限一次，你可与一名其他角色交替重铸一张牌，直至所有重铸牌点数不为递减。若最后一张重铸牌为"..
  "<font color='red'>♥</font>，重铸者回复1点体力。",
  ["#rfenghou__yanyu"] = "燕语：选择重铸一张牌，并选择一名其他角色，令其与你交替重铸牌！",
  ["#rfenghou__yanyu-card"] = "燕语：请重铸一张牌，若点数小于 %arg 令对方继续重铸！",

  ["$rfenghou__qiaoshi1"] = "樵烟亮亮升，待君归来时。",
  ["$rfenghou__qiaoshi2"] = "青翠枝繁茂，采拾心欢喜。",
  ["$rfenghou__yanyu1"] = "画堂欢燕飞，情许鸳鸯合。",
  ["$rfenghou__yanyu2"] = "欢娱在今夕，燕婉及良时。",
  ["~rfenghou__xiahoushi"] = "柴木潮湿，不可拾取。",
}


local liuche = General:new(extension, "rfenghou__liuche", "han", 4)

local rfenghou__kewang = fk.CreateTriggerSkill{
  name = "rfenghou__kewang",
  events = {fk.CardUseFinished, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.CardUseFinished and player:getMark("@rfenghou__kewang-turn") == 0 then    
          local useEvent = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
            local use = e.data[1]
            return use.from == player.id
          end, Player.HistoryTurn)[1]
          return useEvent and useEvent.data[1] == data
      elseif event == fk.CardUsing then
        return data.card.number ~= 0 and type(player:getMark("@rfenghou__kewang-turn")) == "number"
        and player:getMark("@rfenghou__kewang-turn") ~= 0
        and data.card.number % player:getMark("@rfenghou__kewang-turn") == 0
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUseFinished and player:getMark("@rfenghou__kewang-turn") == 0 then
      player:drawCards(1, self.name)
      player.room:setPlayerMark(player, "@rfenghou__kewang-turn", data.card.number == 0 and "x" or data.card.number)    
    elseif event == fk.CardUsing then
      player:drawCards(1, self.name)
    end
  end,
}
liuche:addSkill(rfenghou__kewang)

local rfenghou__wuying = fk.CreateActiveSkill{
  name = "rfenghou__wuying$",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#rfenghou__wuying",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Self.id ~= to_select and #selected_cards > 0
  end,
  can_use = function(self, player)
    return true
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local cid = effect.cards[1]
    if not cid then return end
    room:obtainCard(to, cid, true, fk.ReasonGive, player.id, self.name)
    if table.contains(to:getCardIds("h"), cid) and Fk:getCardById(cid).trueName == "slash" and to.kingdom == "han" then
      U.askForUseRealCard(player.room, to, {cid}, ".", self.name, nil, nil, false, false)
    end
  end,
}
liuche:addSkill(rfenghou__wuying)
AddWinAudio(liuche)

Fk:loadTranslationTable{
  ["rfenghou__liuche"] = "刘彻",
  ["#rfenghou__liuche"] = "汉武帝",
  ["designer:rfenghou__liuche"] = "低调的温柔",
  ["illustrator:rfenghou__liuche"] = "三国杀十周年",
  ["cv:rfenghou__liuche"] = "折翼",

  ["rfenghou__kewang"] = "可往",
  [":rfenghou__kewang"] = "你每回合首次使用牌后，摸一张牌，且本回合使用与之倍数牌时，再摸一张牌。",
  ["@rfenghou__kewang-turn"] = "可往",

  ["rfenghou__wuying"] = "武英",
  [":rfenghou__wuying"] = "主公技，出牌阶段，你可以将一张【杀】交给一名其他角色，若其为汉势力，令其使用之。",
  ["#rfenghou__wuying"] = "武英：将一张【杀】交给一名角色，若其为汉势力，令其使用之",

  ["$rfenghou__kewang1"] = "寇可往,吾亦可往。",
  ["$rfenghou__kewang2"] = "若得阿娇，当以金屋藏之。",
  ["$rfenghou__wuying1"] = "如此，一击可擒也。",
  ["$rfenghou__wuying2"] = "如此，霸业可图也。",
  ["~rfenghou__liuche"] = "军士死略离散，悲痛常在朕心。",
  ["$rfenghou__liuche_win_audio"] = "许多事只有天知道，你觉得你自己真的了解朕吗？",
}

local liguang = General:new(extension, "rfenghou__liguang", "han", 4)

local rfenghou__feijiang = fk.CreateTriggerSkill{
  name = "rfenghou__feijiang",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return data.extra_data and data.extra_data.rfenghou__feijiangCount and data.extra_data.rfenghou__feijiangCount[player.id] ~= nil
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local count = data.extra_data.rfenghou__feijiangCount[player.id]
    local cards = table.filter(room.draw_pile, function(id) return Fk:getCardById(id).is_damage_card end)
    if #cards > 0 then
      room:obtainCard(player, table.random(cards, count), true, fk.ReasonJustMove, player.id, self.name)
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local mark, n = player:getMark("@rfenghou__feijiang-turn"), 0
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        n = n + #move.moveInfo
      end
    end
    local count = ((mark+n) // 6) - (mark // 6)
    if count > 0 then
      data.extra_data = data.extra_data or {}
      data.extra_data.rfenghou__feijiangCount = data.extra_data.rfenghou__feijiangCount or {}
      data.extra_data.rfenghou__feijiangCount[player.id] = count
    end
    player.room:addPlayerMark(player, "@rfenghou__feijiang-turn", n)
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@rfenghou__feijiang-turn", 0)
  end,
}
liguang:addSkill(rfenghou__feijiang)

Fk:loadTranslationTable{
  ["rfenghou__liguang"] = "李广",
  ["#rfenghou__liguang"] = "",
  ["designer:rfenghou__liguang"] = "Romantic",
  ["illustrator:rfenghou__liguang"] = "三国杀十周年",

  ["rfenghou__feijiang"] = "飞将",
  [":rfenghou__feijiang"] = "每回合内，每六张牌进入弃牌堆时，你检索一张伤害牌。",
  ["@rfenghou__feijiang-turn"] = "飞将",
}

local weizifu = General:new(extension, "rfenghou__weizifu", "han", 3, 3, General.Female)

local rfenghou__jianqi = fk.CreateActiveSkill{
  name = "rfenghou__jianqi",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#rfenghou__jianqi",
  interaction = function(self)
    return UI.ComboBox { choices = {"rfenghou__jianqi_choose", "rfenghou__jianqi_top"} }
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) < 2
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local generals = table.filter(room.general_pile, function(name)
      return Fk.generals[name].kingdom == to.kingdom
    end)
    if #generals == 0 then return end
    local general = generals[1]
    if self.interaction.data == "rfenghou__jianqi_choose" then
      general = room:askForGeneral(to, table.random(generals, 3), 1, true)
    end
    room:findGeneral(general)
    room:changeHero(to, general, false, false, true, true)
  end,
}
weizifu:addSkill(rfenghou__jianqi)

Fk:loadTranslationTable{
  ["rfenghou__weizifu"] = "卫子夫",
  ["#rfenghou__weizifu"] = "",
  ["designer:rfenghou__weizifu"] = "Romantic",
  ["illustrator:rfenghou__weizifu"] = "三国杀十周年",

  ["rfenghou__jianqi"] = "荐戚",
  [":rfenghou__jianqi"] = "每局游戏限两次，出牌阶段，你可以选择一种变更规则并令一名角色按此规则变更武将牌。"..
  "<br>*变更规则：1.从三张同势力武将牌中选择一张；2.替换武将牌为武将牌堆中首张同势力武将。",
  ["#rfenghou__jianqi"] = "荐戚：你可以令一名角色变更武将牌",
  ["rfenghou__jianqi_choose"] = "从三张同势力武将牌中选择一张",
  ["rfenghou__jianqi_top"] = "替换为武将牌堆中首张同势力武将",
}

return extension
